﻿using System;
using System.ComponentModel.DataAnnotations.Schema;
using Volo.Abp.Domain.Entities;

namespace CommonManagement
{
    /// <summary>
    /// 新闻评论类
    /// </summary>
    public class Comment : Entity<int>
    {
        /// <summary>应用类型</summary>
        public string AppType { get; protected set; }

        /// <summary>新闻Id</summary>
        public int NewsId { get; protected set; }

        /// <summary>评论人Id</summary>
        public int UserId { get; protected set; }

        /// <summary>内容</summary>
        public string Content { get; protected set; }

        /// <summary>点赞数</summary>
        public int LikeNum { get; protected set; }

        /// <summary>评论时间</summary>
        public DateTime CommentDate { get; protected set; }

        /// <summary>新闻</summary>
        [ForeignKey("NewsId")]
        public Press Press { get; protected set; }

        /// <summary>用户</summary>
        [ForeignKey("UserId")]
        public User User { get; protected set; }

        private Comment() { }

        internal Comment(
            string appType,
            int newsId,
            int userId,
            string content)
        {
            AppType = appType;
            NewsId = newsId;
            UserId = userId;
            Content = content;
            LikeNum = 0;
            CommentDate = DateTime.Now;
        }

        /// <summary>
        /// 点赞
        /// </summary>
        public Comment Like()
        {
            this.LikeNum++;
            return this;
        }
    }
}